
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.common.keys import Keys
# from selenium.webdriver.common.action_chains import ActionChains
# import unittest
# import time
# class baidu(unittest.TestCase):
#     def test_search(self):
#         self.driver=webdriver.Chrome()
#         self.driver.get('https://www.baidu.com/')
#         search=self.driver.find_element(By.ID,'kw')
#         search.send_keys('自动化搜索')
#         search.send_keys(Keys.ENTER)
#         # 鼠标右键
#         # ActionChains(self.driver).context_click(search).perform()
#         # time.sleep(2)
#         # 鼠标双击
#         ActionChains(self.driver).double_click(search).click(search).perform()
#         time.sleep(2)
#         # 键盘复制
#         search.send_keys(Keys.CONTROL, 'c')
#         time.sleep(2)
#         # 设置 鼠标悬停
#         set = self.driver.find_element(By.CLASS_NAME, 'pf')
#         ActionChains(self.driver).move_to_element(set).perform()
#         time.sleep(10)
#         # 高级搜索
#         self.driver.find_element(By.LINK_TEXT, '高级搜索').click()
#         time.sleep(2)
#         # 输入框1q
#         q1=self.driver.find_element(By.NAME,'q1')
#         q1.send_keys(Keys.CONTROL,'v')
#         time.sleep(2)
#         self.driver.find_element(By.CLASS_NAME,'c-select-selected-value').click()
#         time.sleep(2)
#         self.driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[4]').click()
#         time.sleep(2)
#         self.driver.find_element(By.CLASS_NAME,'advanced-search-btn c-btn c-btn-primary switch-button').click()
#         time.sleep(5)
import unittest,time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.baidu.com/')
        self.driver.maximize_window()
    def tearDown(self):
        time.sleep(10)
        self.driver.quit()
    def test_search(self):
        search=self.driver.find_element(By.ID,'kw')
        search.send_keys("web自动化测试")
        search.send_keys(Keys.ENTER)
        time.sleep(3)
        #鼠标右键
        # ActionChains(self.driver).context_click(search).perform()
        # time.sleep(2)

        # 鼠标双击
        ActionChains(self.driver).click(search).double_click(search).perform()
        time.sleep(10)
        #键盘复制
        # search.send_keys(Keys.CONTROL, 'a')
        # time.sleep(2)
        search.send_keys(Keys.CONTROL,'c')
        time.sleep(2)
        #设置 鼠标悬停
        set=self.driver.find_element(By.CLASS_NAME,'pf')
        ActionChains(self.driver).move_to_element(set).perform()
        time.sleep(10)
        #高级搜索
        self.driver.find_element(By.LINK_TEXT,'高级搜索').click()
        time.sleep(2)
        #输入框1 q1
        q1=self.driver.find_element(By.NAME,'q1')
        q1.send_keys(Keys.CONTROL,'v')
        time.sleep(3)
        #双击输入框1的内容 复制  剪切到输入框4中
        ActionChains(self.driver).double_click(q1).perform()
        time.sleep(2)
        q1.send_keys(Keys.CONTROL,'c')
        time.sleep(2)
        q1.send_keys(Keys.CONTROL,'x')
        time.sleep(2)
        #粘贴
        self.driver.find_element(By.NAME,'q4').send_keys(Keys.CONTROL,'v')
        time.sleep(5)
        self.driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[1]/i[1]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[5]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[1]/i[1]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[2]/div[2]/p[3]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH,'//*[@id="adv-setting-8"]/input[2]').click()
        time.sleep(5)

    def test_search_01(self):
        search = self.driver.find_element(By.ID, 'kw')
        search.send_keys("web自动化测试2")
        search.send_keys(Keys.ENTER)
        time.sleep(3)
        # 鼠标双击
        ActionChains(self.driver).click(search).double_click(search).perform()
        time.sleep(10)
        search.send_keys(Keys.CONTROL, 'c')
        time.sleep(2)
        # 高级搜索
        self.driver.find_element(By.LINK_TEXT, '高级搜索').click()
        time.sleep(2)
        # 输入框1 q1
        q1 = self.driver.find_element(By.NAME, 'q1')
        q1.send_keys(Keys.CONTROL, 'v')
        time.sleep(3)
        # 双击输入框1的内容 复制  剪切到输入框4中
        ActionChains(self.driver).double_click(q1).perform()
        time.sleep(2)
        # 粘贴
        self.driver.find_element(By.NAME, 'q4').send_keys(Keys.CONTROL, 'v')
        time.sleep(5)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-gpc"]/div/div[1]/i[1]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[5]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[1]/i[1]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[2]/div[2]/p[3]').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-8"]/input[2]').click()
        time.sleep(5)



if __name__ == '__main__':
    unittest.main()
